import { Entity, PrimaryGeneratedColumn, ManyToMany, Column,JoinTable } from 'typeorm';
import { UsersEntity } from '../users/users.entity';
import { RouteEntity } from '../route/route.entity';

@Entity({ name: 'access' })
export class AccessEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column('varchar')
  name: string;

  @Column('varchar')
  field: string;

  @Column('int')
  state: number;

  @Column('varchar')
  describe: string;

  @Column('datetime')
  createDate: string;

  @Column('float')
  order: number;

  //预留菜单字段

  @ManyToMany(
    type => UsersEntity,
    user => user.access,
    { cascade: true },
  )
  users: UsersEntity[];

  @ManyToMany(
    type => RouteEntity,
    route => route.access,
  )
  @JoinTable({
    name: 'access_route',
    joinColumns: [{ name: 'access_id' }],
    inverseJoinColumns: [{ name: 'route_id' }],
  })
  routes: RouteEntity[];
}
